package com.ww.springboot.boot.test;

import cn.hutool.http.HttpRequest;
import com.ww.springboot.boot.utils.Func;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.List;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2025-02-05 11:55
 */
public class OmsTestCommon {

    public static void main(String[] args) throws IOException {
        String format0 = "{\"data\":[{\"omOrderId\":\"%s\",\"packageCode\":\"%s\",\"ifPass\":0,\"remarks\":\"\"}]}";
        String format1 = "{\"data\":[{\"packageCode\":\"%s\",\"packageStatus\":5,\"reason\":\"申报价格变更\",\"originalPlatOrderId\":\"\",\"cancelType\":\"14\"}]}";
        String format2 = "{\"data\":[{\"packageCode\":\"%s\",\"packageStatus\":11,\"reason\":\"申报价格变更\",\"originalPlatOrderId\":\"\"}]}";
        String format3 = "{\"data\":[{\"omOrderId\":\"%s\",\"exceptionType\":2,\"ifForecast\":null,\"ifPass\":1,\"remarks\":\"\",\"originalPlatOrderId\":\"\",\"deficitType\":\"\",\"packageCode\":\"%s\"}]}";
        ClassPathResource classPathResource = new ClassPathResource("/static/text/code.txt");
        String code = IOUtils.toString(classPathResource.getInputStream(), "utf-8");
        List<String> strList = Func.toStrList("\r\n", code);
        strList.parallelStream().forEach(one->{
            List<String> codeList = Func.toStrList("\t", one);
            //            出库拦截
            String body = HttpRequest.post("oms-service.box-tools.com/packageMain/blockAudit")
                    .header("tenantId", codeList.get(1))
                    .body(String.format(format0, codeList.get(0).substring(0,codeList.get(0).length()-1),codeList.get(0)))
                    .execute()
                    .body();
            System.out.println(body);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
//            //1.撤销包裹
//            String body = HttpRequest.post("oms-service.box-tools.com/packageMain/cancelPackage")
//                    .header("tenantId", codeList.get(1))
//                    .body(String.format(format1, codeList.get(0)))
//                    .execute()
//                    .body();
//            System.out.println(body);
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
            //2.恢复包裹
            body = HttpRequest.post("oms-service.box-tools.com/packageMain/recoveryPackage")
                    .header("tenantId", codeList.get(1))
                    .body(String.format(format2, codeList.get(0)))
                    .execute().body();
            System.out.println(body);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //3.审核包裹
            body = HttpRequest.post("oms-service.box-tools.com/packageMain/exceptionAudit")
                    .header("tenantId",codeList.get(1))
                    .body(String.format(format3, codeList.get(0).substring(0,codeList.get(0).length()-1),codeList.get(0)))
                    .execute().body();
            System.out.println(body);
        });

    }
}
